//
//  UITableView+TP.m
//  Tripvi
//
//  Created by xiaowuxiaowu on 2017/5/18.
//  Copyright © 2017年 xiaowuxiaowu. All rights reserved.
//

#import "UITableView+TP.h"

@implementation UITableView (TP)
-(UIButton *)tp_addFooterWithFrame:(CGRect)frame buttonHeight:(CGFloat)height title:(NSString *)title toBlock:(TouchedBlock)block{
  
    UIView *footerView = [self tp_addFooterWithFrame:frame];
    TPButton *payButton = [TPButton buttonWithTitle:title toHeight:height ActionHandler:block];
    [payButton tp_arrow];
    [footerView addSubview:payButton];
    [payButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(self.mas_width).multipliedBy(0.7);
        make.centerX.mas_equalTo(self.superview);
        make.height.mas_equalTo(height);
        make.centerY.mas_equalTo(footerView);
    }];
    
    return payButton;
    
}
-(UIView *)tp_addFooterWithFrame:(CGRect)frame{
    
    UIView *footerView = [[UIView alloc]initWithFrame:frame];
    self.tableFooterView = footerView;
    
    return footerView;
    
}
-(UIView *)tp_addheaderWithFrame:(CGRect)frame{
    
    UIView *headerView = [[UIView alloc]initWithFrame:frame];
    self.tableHeaderView = headerView;
    
    return headerView;
    
}

- (void)reloadDataWithAnimated:(BOOL)animated
{
    [self reloadData];
    
    if (animated) {
        CATransition *animation = [CATransition animation];
        [animation setType:kCATransitionFade];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
        [animation setDuration:0.3];
        [[self layer] addAnimation:animation forKey:@"UITableViewReloadDataAnimationKey"];
    }
}
@end
